<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<input type="button" value="轮换背景">
<input type="button" value="停">	
<script>
	var aBtn = document.getElementsByTagName('input');
	var arr = ['1.jpg','2.jpg','3.jpg','4.jpg'];
	var num =0;
	var timer = null;

	aBtn[0].onclick = function (){
		clearInterval(timer);
		timer = setInterval(function(){
			document.body.style.background = 'url('+ arr[num] +')';
			num++;
			num %= arr.length;	//取模%和=不能有空格
		},1000)
		//document.body.style.background = 'url('+ arr[num] +')';		//括号内是字符串，注意单引号的位置
	}
	
	aBtn[1].onclick = function(){
		clearInterval(timer)
	}
</script>
</body>
</html>

</body>
</html>
